/*
 *Copyright 2021-2023 NERCIS
 *
 *Licensed under the Apache License, Version 2.0 (the "License");
 *you may not use this file except in compliance with the License.
 *You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 *Unless required by applicable law or agreed to in writing, software
 *distributed under the License is distributed on an "AS IS" BASIS,
 *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *See the License for the specific language governing permissions and
 *limitations under the License.
 */

package cn.ac.nercis.pes.community.controller.project;

import cn.ac.nercis.pes.common.constant.common.BaseConstants;
import cn.ac.nercis.pes.community.component.controls.CustomScrollPane;
import cn.ac.nercis.pes.community.component.dialog.MessageDialog;
import cn.ac.nercis.pes.community.component.dialog.MessageType;
import cn.ac.nercis.pes.community.component.dialog.PageDialog;
import cn.ac.nercis.pes.community.component.dialog.SpinnerDialog;
import cn.ac.nercis.pes.community.support.FXMLController;
import cn.ac.nercis.pes.community.support.event.CommonCallback;
import cn.ac.nercis.pes.model.dto.project.ImportConflictDTO;
import cn.ac.nercis.pes.model.dto.project.SystemDTO;
import cn.ac.nercis.pes.model.standard.ImportStage;
import cn.ac.nercis.pes.service.project.SystemImportService;
import javafx.application.Platform;
import javafx.beans.property.SimpleObjectProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.net.URL;
import java.util.List;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * 系统数据导入控制器
 *
 * @author zpy
 * @version 1.0.0
 */
@Slf4j
@FXMLController
public class SystemImportController implements Initializable {

    private final SystemImportService systemImportService;
    private final SimpleObjectProperty<ImportStage> importStage = new SimpleObjectProperty<>();
    @FXML
    private StackPane importBodyPane;
    @FXML
    private Label titleLbl;
    @FXML
    private HBox optionBox;
    @FXML
    private ToggleGroup optionGroup;
    @FXML
    private RadioButton coverRb;
    @FXML
    private RadioButton skipRb;
    @FXML
    private CustomScrollPane confirmScrollPanel;
    @FXML
    private VBox errorBox;
    @FXML
    private Label errorInfo;
    @FXML
    private Button importButton;
    @FXML
    private Button closeButton;
    @FXML
    private GridPane conflictDataGrid;
    private SpinnerDialog spinnerDialog;
    private PageDialog pageDialog;
    private SystemDTO systemInfo;
    private String systemId;
    private CommonCallback successCall;

    public SystemImportController(SystemImportService systemImportService) {
        this.systemImportService = systemImportService;
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        spinnerDialog = SpinnerDialog.builder().withContainer(importBodyPane).build();

        optionBox.managedProperty().bind(optionBox.visibleProperty());
        importButton.managedProperty().bind(importButton.visibleProperty());
        closeButton.managedProperty().bind(closeButton.visibleProperty());
        conflictDataGrid.managedProperty().bind(conflictDataGrid.visibleProperty());
        importStage.addListener((observable, oldValue, newValue) -> {
            if (Objects.nonNull(newValue)) {
                this.titleLbl.setText(newValue.getName());
            }
        });
    }

    public void initData(PageDialog pageDialog, SystemDTO systemInfo, CommonCallback successCall) {
        this.pageDialog = pageDialog;
        this.systemInfo = systemInfo;
        this.successCall = successCall;
        this.errorBox.setVisible(false);
        this.optionBox.setVisible(true);
        this.confirmScrollPanel.setVisible(true);
        this.checkSystemBaseData();
    }

    @FXML
    public void onClose() {
        pageDialog.close();
    }

    @FXML
    public void onImport() {
        Toggle toggleGroup = optionGroup.getSelectedToggle();
        if (Objects.isNull(toggleGroup) || !(toggleGroup instanceof RadioButton)) {
            MessageDialog.builder()
                    .withType(MessageType.WARN).withMessage("请选择覆盖或跳过当前导入的数据")
                    .withContainer(this.importBodyPane)
                    .build().show();
            return;
        }
        boolean cover = StringUtils.equals(((RadioButton) toggleGroup).getText(), "覆盖");
        switch (this.importStage.get()) {
            case SYSTEM_BASE:
                this.importSystemBaseData(cover);
                break;
            case SYSTEM_TARGET:
                this.importSystemTargetData(cover);
                break;
            case SYSTEM_SPECIAL_TARGET:
                this.importSpecialTargetData(cover);
                break;
            case SYSTEM_PHOTO_FILES:
                this.importSystemPhotoFiles(cover);
                break;
            case SYSTEM_PROCESS:
                this.importSystemProcess(cover);
                break;
            case EVALUATION_PROCESS:
                this.importEvaluationProcess(cover);
                break;
            case EVALUATION_CONTENT:
                this.importEvaluationContent(cover);
                break;
            case EVALUATOR:
                this.importEvaluator(cover);
                break;
            case EVALUATION_TOOLS:
                this.importEvaluationTools(cover);
                break;
            case PASSWORD_SERVER:
                this.importPasswordServer(cover);
                break;
            case SECURITY_THREAT:
                this.importSecurityThreat(cover);
                break;
            case PERSONNEL:
                this.importPersonnel(cover);
                break;
            case SECURITY_DOCUMENT:
                this.importSecurityDocument(cover);
                break;
            case ASSET:
                this.importAssetData(cover);
                break;
            case EVALUATION_METHOD:
                this.importEvaluationMethod(cover);
                break;
            case EVALUATION_REQUIRE:
                this.importEvaluationRequire(cover);
                break;
            case EVALUATION_RECORD:
                this.importEvaluationRecord(cover);
                break;
            case UNIT_EVALUATION:
                this.importUnitEvaluation(cover);
                break;
            case RESULT_CORRECTION:
                this.importResultCorrection(cover);
                break;
            case RISK_ANALYSIS:
                this.importRiskAnalysis(cover);
                break;
            case EVALUATOR_QUALIFICATION:
                this.importProof(cover);
                break;
            case EVALUATION_REPORT:
                this.importReport(cover);
                break;
        }
    }

    private void checkSystemBaseData() {
        this.spinnerDialog.show();
        this.importStage.set(ImportStage.SYSTEM_BASE);
        notifyProcess(0.1, "校验系统基础数据中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkSystemBaseData(systemInfo.getId()))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importSystemBaseData(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("校验系统基础数据出错!");
                    log.error("校验系统基础数据出错!", ex);
                    return null;
                });
    }

    private void importSystemBaseData(Boolean cover) {
        notifyProcess("正在导入系统基础数据...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importSystemBaseData(systemInfo.getId(), cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.systemId = res.getData();
                        this.checkSystemTargetData();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入系统基础数据出错!");
                    log.error("导入系统基础数据出错!", ex);
                    return null;
                });
    }

    private void checkSystemTargetData() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.SYSTEM_TARGET);
        notifyProcess(0.2, "检查系统指标数据中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkSystemTargetData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importSystemTargetData(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查系统指标数据出错!");
                    log.error("检查系统指标数据出错!", ex);
                    return null;
                });
    }

    private void importSystemTargetData(Boolean cover) {
        notifyProcess("正在导入系统指标数据...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importSystemTargetData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkSpecialTargetData();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入系统指标数据出错!");
                    log.error("导入系统指标数据出错!", ex);
                    return null;
                });

    }

    private void checkSpecialTargetData() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.SYSTEM_SPECIAL_TARGET);
        notifyProcess(0.2, "检查系统特殊指标数据中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkSpecialTargetData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importSpecialTargetData(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查系统特殊指标数据出错!");
                    log.error("检查系统特殊指标数据出错!", ex);
                    return null;
                });
    }

    private void importSpecialTargetData(Boolean cover) {
        notifyProcess("正在导入系统特殊指标数据...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importSpecialTargetData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkSystemPhotoFiles();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入系统特殊指标数据出错!");
                    log.error("导入系统特殊指标数据出错!", ex);
                    return null;
                });

    }

    private void checkSystemPhotoFiles() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.SYSTEM_PHOTO_FILES);
        notifyProcess(0.3, "检查系统证据文件中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkSystemFiles(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importSystemPhotoFiles(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查系统证据文件出错!");
                    log.error("检查系统证据文件出错!", ex);
                    return null;
                });
    }

    private void importSystemPhotoFiles(Boolean cover) {
        notifyProcess("正在导入系统证据文件...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importSystemFiles(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkSystemProcess();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入系统证据文件出错!");
                    log.error("导入系统证据文件出错!", ex);
                    return null;
                });

    }

    private void checkSystemProcess() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.SYSTEM_PROCESS);
        notifyProcess(0.3, "检查系统测评进度信息中...");
        CompletableFuture.supplyAsync(this.systemImportService::checkSystemProcessData)
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importSystemProcess(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查系统测评进度信息出错!");
                    log.error("检查系统测评进度信息出错!", ex);
                    return null;
                });
    }

    private void importSystemProcess(Boolean cover) {
        notifyProcess("正在导入系统测评进度信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importSystemProcessData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkEvaluationProcess();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入系统测评进度信息出错!");
                    log.error("导入系统测评进度信息出错!", ex);
                    return null;
                });

    }

    private void checkEvaluationProcess() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.spinnerDialog.show();
        this.importStage.set(ImportStage.EVALUATION_PROCESS);
        notifyProcess(0.4, "检查测评过程信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkEvaluationProcessData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importEvaluationProcess(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查测评过程信息出错!");
                    log.error("检查测评过程信息出错!", ex);
                    return null;
                });
    }

    private void importEvaluationProcess(Boolean cover) {
        notifyProcess("正在导入测评过程信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importEvaluationProcessData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkEvaluationContent();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入测评过程信息出错!");
                    log.error("导入测评过程信息出错!", ex);
                    return null;
                });
    }

    private void checkEvaluationContent() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.EVALUATION_CONTENT);
        notifyProcess(0.4, "检查测评内容数据中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkEvaluationContentData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importEvaluationContent(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查测评内容信息出错!");
                    log.error("检查测评内容信息出错!", ex);
                    return null;
                });
    }

    private void importEvaluationContent(Boolean cover) {
        notifyProcess("正在导入测评内容数据...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importEvaluationContentData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkEvaluator();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入测评内容信息出错!");
                    log.error("导入测评内容信息出错!", ex);
                    return null;
                });
    }

    private void checkEvaluator() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.EVALUATOR);
        notifyProcess(0.4, "检查测评项目组成员信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkEvaluatorData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importEvaluator(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查测评项目组成员信息出错!");
                    log.error("检查测评项目组成员信息出错!", ex);
                    return null;
                });
    }

    private void importEvaluator(Boolean cover) {
        notifyProcess("正在导入测评项目组成员信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importEvaluatorData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkEvaluationTools();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入测评项目组成员信息出错!");
                    log.error("导入测评项目组成员信息出错!", ex);
                    return null;
                });
    }

    private void checkEvaluationTools() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.EVALUATION_TOOLS);
        notifyProcess(0.4, "检查测评工具信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkEvaluationToolsData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importEvaluationTools(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查测评工具信息出错!");
                    log.error("检查测评工具信息出错!", ex);
                    return null;
                });
    }

    private void importEvaluationTools(Boolean cover) {
        notifyProcess("正在导入测评工具信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importEvaluationToolsData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkPasswordServer();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入测评工具信息出错!");
                    log.error("导入测评工具信息出错!", ex);
                    return null;
                });
    }

    private void checkPasswordServer() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.PASSWORD_SERVER);
        notifyProcess(0.4, "检查密码服务信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkPasswordServerData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importPasswordServer(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查密码服务信息出错!");
                    log.error("检查密码服务信息出错!", ex);
                    return null;
                });
    }

    private void importPasswordServer(Boolean cover) {
        notifyProcess("正在导入密码服务信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importPasswordServerData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkSecurityThreat();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入密码服务信息出错!");
                    log.error("导入密码服务信息出错!", ex);
                    return null;
                });
    }

    private void checkSecurityThreat() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.SECURITY_THREAT);
        notifyProcess(0.4, "检查安全威胁信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkSecurityThreatData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importSecurityThreat(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查安全威胁信息出错!");
                    log.error("检查安全威胁信息出错!", ex);
                    return null;
                });
    }

    private void importSecurityThreat(Boolean cover) {
        notifyProcess("正在导入安全威胁信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importSecurityThreatData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkPersonnel();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入安全威胁信息出错!");
                    log.error("导入安全威胁信息出错!", ex);
                    return null;
                });
    }

    private void checkPersonnel() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.PERSONNEL);
        notifyProcess(0.4, "检查人员（系统资产）信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkPersonnelData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importPersonnel(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查人员（系统资产）信息出错!");
                    log.error("检查人员（系统资产）信息出错!", ex);
                    return null;
                });
    }

    private void importPersonnel(Boolean cover) {
        notifyProcess("正在导入人员（系统资产）信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importPersonnelData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkSecurityDocument();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入人员（系统资产）信息出错!");
                    log.error("导入人员（系统资产）信息出错!", ex);
                    return null;
                });
    }

    private void checkSecurityDocument() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.SECURITY_DOCUMENT);
        notifyProcess(0.4, "检查安全管理文档信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkSecurityDocumentData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importSecurityDocument(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查安全管理文档信息出错!");
                    log.error("检查安全管理文档信息出错!", ex);
                    return null;
                });
    }

    private void importSecurityDocument(Boolean cover) {
        notifyProcess("正在导入安全管理文档信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importSecurityDocumentData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkAssetData();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入安全管理文档信息出错!");
                    log.error("导入安全管理文档信息出错!", ex);
                    return null;
                });
    }

    private void checkAssetData() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.ASSET);
        notifyProcess(0.5, "检查系统资产信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkAssetData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importAssetData(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查系统资产信息出错!");
                    log.error("检查系统资产信息出错!", ex);
                    return null;
                });
    }

    private void importAssetData(Boolean cover) {
        notifyProcess("正在导入系统资产信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importAssetData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkEvaluationMethod();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入系统资产信息出错!");
                    log.error("导入系统资产信息出错!", ex);
                    return null;
                });
    }

    private void checkEvaluationMethod() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.EVALUATION_METHOD);
        notifyProcess(0.6, "检查资产测评方式信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkEvaluationMethodData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importEvaluationMethod(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查资产测评方式信息出错!");
                    log.error("检查资产测评方式信息出错!", ex);
                    return null;
                });
    }

    private void importEvaluationMethod(Boolean cover) {
        notifyProcess("正在导入资产测评方式信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importEvaluationMethodData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkEvaluationRequire();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入资产测评方式信息出错!");
                    log.error("导入资产测评方式信息出错!", ex);
                    return null;
                });
    }

    private void checkEvaluationRequire() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.EVALUATION_REQUIRE);
        notifyProcess(0.6, "检查测评配合需求信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkEvaluationRequireData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importEvaluationRequire(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查测评配合需求信息出错!");
                    log.error("检查测评配合需求信息出错!", ex);
                    return null;
                });
    }

    private void importEvaluationRequire(Boolean cover) {
        notifyProcess("正在导入测评配合需求信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importEvaluationRequireData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkEvaluationRecord();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入测评配合需求信息出错!");
                    log.error("导入测评配合需求信息出错!", ex);
                    return null;
                });
    }

    private void checkEvaluationRecord() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.EVALUATION_RECORD);
        notifyProcess(0.7, "检查现场测评记录信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkEvaluationRecordData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importEvaluationRecord(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查现场测评记录信息出错!");
                    log.error("检查现场测评记录信息出错!", ex);
                    return null;
                });
    }

    private void importEvaluationRecord(Boolean cover) {
        notifyProcess("正在导入现场测评记录信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importEvaluationRecordData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkUnitEvaluation();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入现场测评记录信息出错!");
                    log.error("导入现场测评记录信息出错!", ex);
                    return null;
                });
    }

    private void checkUnitEvaluation() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.UNIT_EVALUATION);
        notifyProcess(0.8, "检查单元测评信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkUnitEvaluationData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importUnitEvaluation(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查单元测评信息出错!");
                    log.error("检查单元测评信息出错!", ex);
                    return null;
                });
    }

    private void importUnitEvaluation(Boolean cover) {
        notifyProcess("正在导入单元测评信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importUnitEvaluationData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkResultCorrection();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入单元测评信息出错!");
                    log.error("导入单元测评信息出错!", ex);
                    return null;
                });
    }

    private void checkResultCorrection() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.RESULT_CORRECTION);
        notifyProcess(0.8, "检查测评结果修正信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkResultCorrectionData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importResultCorrection(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("检查测评结果修正信息出错!");
                    log.error("检查测评结果修正信息出错!", ex);
                    return null;
                });
    }

    private void importResultCorrection(Boolean cover) {
        notifyProcess("正在导入测评结果修正信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importResultCorrectionData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkRiskAnalysis();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    spinnerDialog.close();
                    this.systemImportService.clearData();
                    renderErrorInfo("导入测评结果修正信息出错!");
                    log.error("导入测评结果修正信息出错!", ex);
                    return null;
                });
    }

    private void checkRiskAnalysis() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.RISK_ANALYSIS);
        notifyProcess(0.9, "检查风险分析信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkRiskAnalysisData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importRiskAnalysis(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    this.systemImportService.clearData();
                    log.error("检查风险分析信息出错!", ex);
                    return null;
                });
    }

    private void importRiskAnalysis(Boolean cover) {
        notifyProcess("正在导入风险分析信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importRiskAnalysisData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkProof();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    this.systemImportService.clearData();
                    log.error("导入风险分析信息出错!", ex);
                    return null;
                });
    }

    private void checkProof(){
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.EVALUATOR_QUALIFICATION);
        notifyProcess(0.9, "检查密评人员资格信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkEvaluatorQualificationData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importProof(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    this.systemImportService.clearData();
                    log.error("检查密评人员资格信息出错!", ex);
                    return null;
                });
    }

    private void importProof(Boolean cover){
        notifyProcess("正在导入密评人员资格情况信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importEvaluatorQualificationData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        this.checkReport();
                    } else {
                        this.spinnerDialog.close();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    this.systemImportService.clearData();
                    log.error("导入密评人员资格情况信息出错!", ex);
                    return null;
                });
    }

    private void checkReport() {
        this.conflictDataGrid.setVisible(false);
        this.optionBox.setVisible(false);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(false);
        if (!this.spinnerDialog.isShow()) {
            this.spinnerDialog.show();
        }
        this.importStage.set(ImportStage.EVALUATION_REPORT);
        notifyProcess(1, "检查报告生成信息中...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.checkReportData(this.systemId))
                .thenAccept(res -> Platform.runLater(() -> {
                    if (res.isSuccess()) {
                        if (CollectionUtils.isEmpty(res.getData())) {
                            importReport(true);
                        } else {
                            renderCommonConflictData(res.getData());
                        }
                    } else {
                        spinnerDialog.close();
                        this.systemImportService.clearData();
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    log.error("检查报告生成信息出错!", ex);
                    return null;
                });
    }

    private void importReport(Boolean cover) {
        notifyProcess("正在导入报告生成信息...");
        CompletableFuture.supplyAsync(() -> this.systemImportService.importReportData(this.systemId, cover))
                .thenAccept(res -> Platform.runLater(() -> {
                    this.spinnerDialog.close();
                    if (res.isSuccess()) {
                        this.pageDialog.close();
                        this.systemImportService.clearData();
                        MessageDialog.builder()
                                .withType(MessageType.SUCCESS).withMessage("数据导入成功")
                                .build().show();
                        if(Objects.nonNull(successCall)){
                            successCall.action();
                        }
                    } else {
                        renderErrorInfo(res.getMsg());
                    }
                }))
                .exceptionally((ex) -> {
                    this.systemImportService.clearData();
                    log.error("导入报告生成信息出错!", ex);
                    return null;
                });
    }

    private void renderCommonConflictData(List<ImportConflictDTO> conflictData) {
        spinnerDialog.close();
        this.optionBox.setVisible(true);
        this.importButton.setVisible(true);
        this.closeButton.setVisible(true);
        this.titleLbl.setText(this.importStage.getName().concat("冲突数据对比"));
        this.renderConflictData(conflictData);
    }

    private void renderConflictData(List<ImportConflictDTO> conflictData) {
        this.conflictDataGrid.setVisible(true);
        conflictDataGrid.getRowConstraints().clear();
        conflictDataGrid.getChildren().clear();
        this.initGridHead(conflictData.size());
        AtomicInteger dataRowIndex = new AtomicInteger(1);
        conflictData.forEach(data -> renderConflictData(dataRowIndex, data));
    }

    private void renderConflictData(AtomicInteger rowIndex, ImportConflictDTO conflictDTO) {
        AtomicInteger columnIndex = new AtomicInteger(0);
        if (StringUtils.equals(conflictDTO.getFieldName(), BaseConstants.IMPORT_CONFLICT_DATA_TAG)) {
            this.conflictDataGrid.add(generateDataCell(conflictDTO.getOldContent(), "grid-table-cell"),
                    columnIndex.getAndIncrement(), rowIndex.getAndIncrement(), 4, 1);
        } else {
            this.conflictDataGrid.add(generateDataCell(conflictDTO.getFieldName(), "grid-table-cell"),
                    columnIndex.getAndIncrement(), rowIndex.get());
            this.conflictDataGrid.add(generateDataCell(conflictDTO.getOldContent(), "grid-table-cell-left"),
                    columnIndex.getAndIncrement(), rowIndex.get());
            this.conflictDataGrid.add(generateDataCell(conflictDTO.getFieldName(), "grid-table-cell"),
                    columnIndex.getAndIncrement(), rowIndex.get());
            this.conflictDataGrid.add(generateDataCell(conflictDTO.getNewContent(), "grid-table-cell-left"),
                    columnIndex.getAndIncrement(), rowIndex.getAndIncrement());
        }
    }

    private void initGridHead(int dataRowSize) {
        this.initGridRowConstraints(dataRowSize);
        HBox sourceTitleBox = generateHeadCell("已存在数据");
        this.conflictDataGrid.add(sourceTitleBox, 0, 0, 2, 1);
        HBox importTitleBox = generateHeadCell("导入的数据");
        this.conflictDataGrid.add(importTitleBox, 2, 0, 2, 1);
    }

    private void initGridRowConstraints(int dataRowCount) {
        //title row
        IntStream.range(0, 1).forEach(number -> {
            RowConstraints titleRow = new RowConstraints();
            titleRow.setMinHeight(35);
            titleRow.setPrefHeight(35);
            titleRow.setVgrow(Priority.NEVER);
            conflictDataGrid.getRowConstraints().add(titleRow);
        });
        //data row
        IntStream.range(0, dataRowCount).forEach(number -> {
            RowConstraints row = new RowConstraints();
            row.setMinHeight(30);
            row.setVgrow(Priority.SOMETIMES);
            conflictDataGrid.getRowConstraints().add(row);
        });
    }

    private HBox generateHeadCell(String title) {
        HBox hBox = new HBox();
        hBox.getStyleClass().add("grid-table-head");
        hBox.setPadding(new Insets(5, 5, 5, 5));
        Label titleLbl = new Label(title);
        titleLbl.getStyleClass().add("label");
        hBox.getChildren().add(titleLbl);
        return hBox;
    }

    private VBox generateDataCell(String data, String styleCss) {
        if (StringUtils.isEmpty(data)) {
            data = "";
        }
        VBox vBox = new VBox();
        vBox.getStyleClass().add(styleCss);
        vBox.setPadding(new Insets(5, 5, 5, 5));
        Stream.of(data.split(BaseConstants.REGEX_WRAP_TEXT_SPLIT))
                .filter(StringUtils::isNotBlank)
                .forEach(text -> {
                    Label label = new Label(text);
                    label.setWrapText(true);
                    vBox.getChildren().add(label);
                });
        return vBox;
    }

    private void renderErrorInfo(String error) {
        this.titleLbl.setText(this.importStage.getName().concat("导入失败"));
        this.errorInfo.setText(error);
        this.confirmScrollPanel.setVisible(false);
        this.errorBox.setVisible(true);
        this.importButton.setVisible(false);
        this.closeButton.setVisible(true);
    }

    private void notifyProcess(double value, String tip) {
        spinnerDialog.getSpinner().setProgress(value);
        this.notifyProcess(tip);
    }

    private void notifyProcess(String tip) {
        spinnerDialog.setProcessTip(tip);
    }
}
